package com.xuanyuanxinyu.core.base

import android.annotation.SuppressLint
import android.content.Context
import java.lang.NullPointerException

/**
* @FileName:
* @Description:
* @author ken.luo
* @date 2023/4/4
* @version V1.0
* @email 424533553@qq.com
*/
class ContextUtil private constructor() {
    companion object {
        @SuppressLint("StaticFieldLeak")
        private var mContext: Context? = null

        /**
         * 初始化工具类
         *
         * @param context 上下文
         */
        @JvmStatic
        fun init(applicationContext: Context) {
            mContext = applicationContext
        }

        /**
         * 获取ApplicationContext
         *
         * @return ApplicationContext
         */
        @JvmStatic
        fun getContext(): Context {
            if (mContext != null) {
                return mContext as Context
            }
            throw NullPointerException("u should init first")
        }
    }
}